package sm.pzavoli.std;

public class Attributo {
	Object m_value;
	Object m_oldValue;
	ProprietaAttributo m_propAttributo;
	
	public Attributo() {
	}
	public Attributo(ProprietaAttributo attr) {
		m_propAttributo = attr;
	}
	public boolean isNull() {
		return m_value == null;
	}
	public boolean isObbligatorio() {
		return m_propAttributo.isObbligatorio();
	}
	public Object getValue() {
		return m_value;
	}
	public Object getValueNoNull() {
		if ( m_value == null)
			return "null";
		return m_value;
	}
	
	public void setValue(Object value) {
		if ( value instanceof Long && getProp().getType() == ColumnType.DateType)
			m_value = new java.util.Date(((Long)value).longValue());
		else if ( value instanceof Long && getProp().getType() == ColumnType.IntType) {
			int v = ((Long)value).intValue();
			Integer i = Integer.valueOf(v);
			m_value = i;				
		} else {
			m_value = value;
		}
	}
	public ProprietaAttributo getProp() {
		return m_propAttributo;
	}
	/*
	 * Committa le modifiche fatte da un PDC ai singoli attributi
	 */
	public void commit() {
		m_oldValue = m_value;
	}
}
